﻿using System.Linq.Expressions;

namespace Medical.Infrastructrue.Interfaces
{
    public interface IBaseRepository<T> where T : class
    {
        Mycontext DB { get; }
        /// <summary>
        /// 获取所有数据
        /// </summary>
        /// <returns></returns>
        IQueryable<T> GetAll();
        /// <summary>
        /// 根据表达式获取单条数据
        /// </summary>
        /// <param name="expression"> 表达式 </param>
        /// <returns></returns>
        Task<T> GetModel(Expression<Func<T,bool>> expression);
        /// <summary>
        /// 异步插入数据
        /// </summary>
        /// <param name="entity"> 实体 </param>
        /// <returns> 受影响的行数 </returns> 
        Task<int> InsertAsync(T entity);
        /// <summary>
        /// 异步更新数据
        /// </summary>
        /// <param name="entity"> 实体 </param>
        /// <returns> 受影响的行数 </returns>   
        Task<int> UpdateAsync(T entity);
        /// <summary>
        /// 根据Id异步获取单条数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        Task<T> GetByIdAsync(int Id);
        /// <summary>
        /// 新增批量
        /// </summary>
        /// <param name="list">数据</param>
        /// <returns>返回任务</returns>
        Task<int> AddRangeAsync(List<T> list);
        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="list">数据</param>
        /// <returns>返回任务</returns>
        Task<int> UpdateRangeAsync(List<T> list);
        /// <summary>
        /// 批量删除
        /// </summary>
        Task<int> DeleteRangeAsync(List<T> list);

    }
}
